#include<iostream>
#include<unistd.h>
#include<signal.h>
#include<vector>

#define MAX_SIGNUM 31

using namespace std;

void showpending(sigset_t& pending)
{
    for(int n=MAX_SIGNUM;n>=1;--n)
    {
        if(sigismember(&pending,n))
        {
            cout<<"1";
        }
        else
        {
            cout<<"0";
        }
    }
    cout<<endl;
}

void myhandler(int signo)
{
    cout<<signo<<"号信号已被递达"<<endl;
}

int main()
{
    sigset_t block,oblock,pending;
    vector<int> v={2,3};
    for(auto sig:v)
    {
        signal(sig,myhandler);
    }
    sigemptyset(&block);
    sigemptyset(&oblock);
    sigemptyset(&pending);

    for(auto sig:v)
    {
        sigaddset(&block,sig);
    }
    sigprocmask(SIG_SETMASK,&block,&oblock);
    int cnt=10;
    while(true)
    {
        sigpending(&pending);
        showpending(pending);
        sleep(1);
        if(cnt--==0)
        {
            sigprocmask(SIG_SETMASK,&oblock,&block);
            cout<<"恢复信号屏蔽"<<endl;
        }
    }

    return 0;
}